﻿Public Class LiteForm

    Dim LiteControls As New List(Of LiteControl)

    Sub New()
        InitializeComponent()
        DoubleBuffered = True
    End Sub

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        ReplaceControls(Controls, LiteControls)
        Controls.Clear()
        MyBase.OnLoad(e)
    End Sub

    Private Sub ReplaceControls(ByVal Controls As Control.ControlCollection, ByVal LiteControls As List(Of LiteControl))
        For Each Control As Control In Controls
            If TypeOf Control Is HScrollBar Then
                Dim c As New LiteHScrollBar
                c.Transfer(Control)
                LiteControls.Add(c)
            End If
        Next
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
        e.Graphics.FillRectangle(New SolidBrush(BackColor), e.ClipRectangle)
        DrawControls(e.Graphics, LiteControls, e.ClipRectangle)
    End Sub

    Private Sub DrawControls(ByVal g As Graphics, ByVal Controls As List(Of LiteControl), ByVal ClipRectangle As Rectangle)
        For Each Control In LiteControls
            If Control.Bounds.IntersectsWith(ClipRectangle) Then
                g.TranslateTransform(Control.Location.X, Control.Location.Y)
                Control.Draw(g)
                g.ResetTransform()
            End If
        Next
    End Sub

    Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
        MyBase.OnResize(e)
        ResizeControls(LiteControls, ClientRectangle)
        Invalidate()
    End Sub

    Private Sub ResizeControls(ByVal Controls As List(Of LiteControl), ByVal R As Rectangle)
        For Each Control In (From c In Controls Order By Controls.IndexOf(c) Descending)
            Select Case Control.Dock
                Case DockStyle.Right
                    Control.Location = New Point(R.Right - Control.Width, R.Top)
                    Control.Size = New Size(Control.Width, R.Height)
                    R.Width -= Control.Width
                Case DockStyle.Top
                    Control.Location = New Point(R.Left, R.Top)
                    Control.Size = New Size(R.Width, Control.Height)
                    R.Height -= Control.Height
                    R.Offset(0, Control.Height)
                Case DockStyle.Bottom
                    Control.Location = New Point(R.Left, R.Bottom - Control.Height)
                    Control.Size = New Size(R.Width, Control.Height)
                    R.Height -= Control.Height
                Case DockStyle.Left
                    Control.Location = New Point(R.Left, R.Top)
                    Control.Size = New Size(Control.Width, R.Height)
                    R.Width -= Control.Width
                    R.Offset(Control.Width, 0)
                Case DockStyle.Fill
                    Control.Location = R.Location
                    Control.Size = R.Size
            End Select
        Next
    End Sub

End Class

Public MustInherit Class LiteControl
    Public Location As Point
    Public Size As Size
    Public Dock As DockStyle

    ReadOnly Property ClientRectangle As Rectangle
        Get
            Return New Rectangle(New Point(0, 0), Size)
        End Get
    End Property

    ReadOnly Property Bounds As Rectangle
        Get
            Return New Rectangle(Location, Size)
        End Get
    End Property

    Sub Transfer(ByVal c As Control)
        Location = c.Location
        Size = c.Size
        Dock = c.Dock
    End Sub

    MustOverride Sub Draw(ByVal g As Graphics)

    ReadOnly Property Width As Integer
        Get
            Return Size.Width
        End Get
    End Property

    ReadOnly Property Height As Integer
        Get
            Return Size.Height
        End Get
    End Property

End Class

Public Class LiteHScrollBar : Inherits LiteControl

        Public Overrides Sub Draw(ByVal g As System.Drawing.Graphics)
        g.FillRectangle(Brushes.Black, ClientRectangle)
        'ScrollBarRenderer.DrawHorizontalThumb(g, ClientRectangle, VisualStyles.ScrollBarState.Normal)
        'ScrollBarRenderer.DrawHorizontalThumbGrip(g, ClientRectangle, VisualStyles.ScrollBarState.Normal)
        ScrollBarRenderer.DrawLeftHorizontalTrack(g, ClientRectangle, VisualStyles.ScrollBarState.Normal)
        ScrollBarRenderer.DrawArrowButton(g, New Rectangle(0, 0, 16, Height), VisualStyles.ScrollBarArrowButtonState.LeftHot)
        ScrollBarRenderer.DrawArrowButton(g, New Rectangle(Width - 16, 0, 16, Height), VisualStyles.ScrollBarArrowButtonState.RightNormal)
        'Windows.Forms.ControlPaint.DrawScrollButton(g, ClientRectangle, ScrollBarRenderer., ButtonState.Flat)
    End Sub

    End Class